var volte_voice_traffic = []// VOLTE话务量（万Erl）
var upoct = []// LTE数据流量（TB)
var starttime = []
var geoDim = []// 地理纬度子集列表
var HB_province = '河北省'

var shjbd_time = [] // 手机百度
var txw_time = [] // 腾讯网
var jrtt_time = [] // 今日头条
var yemian_time = [] // 页面显示平均时长(ms)    整体

var migu_video_rate = [] //     咪咕视频
var douyin_video_rate = [] //   抖音
var tx_video_rate = [] //       腾讯视频
var aiqyi_video_rate = [] //    爱奇艺视频
var xg_video_rate = [] //       西瓜视频
var hsh_video_rate = [] //      火山小视频
var video_rate = [] //          整体视频下载速率(kbps)

var pic_send_rate = [] //    IM图片发送速率(Kbps)
var pic_receive_rate = [] //    IM图片接收速率(Kbps)
var video_send_rate = [] //    IM视频发送速率(Kbps)
var video_receive_rate = [] //    IM视频接收速率(Kbps)



var drawPage_Json = {}
var high_load_num = []// 高负荷小区数
var basic_comm_complain_ratio = []// 基础通信万投比
var mr_coverage_rate = []// MR覆盖率
var poor_coverage_cell_ratio = []// 弱覆盖小区占比
var critical_alarm_ratio = []// 严重告警小区占比-->严重告警基站占比
var site_num_lte = []// 基站数
var cell_num_lte = []// 小区数
var hige_interfere_num = []// 高干扰小区数
var radio_equipment_availability = []
N.indexHome = N.Class.extend({
    resize: function () {
        // var topheight = $('.container-fluid').height() - $('.content-header').height() - 5;
        var topheight = $('.container-fluid').height() - 20
        var bottomheight = topheight * (1 / 2)
        var boxtop = bottomheight - 120
        var maptop = topheight * (2 / 3) - 60
        var mapbot = topheight * (1 / 3) - 60
        $('.control-size-box').height(boxtop)
        $('.control-size-box-map').height(maptop)
        $('.control-size-box-mapbot').height(mapbot)

        var headheight = $('#table1_wrapper .dataTables_scrollHeadInner').height()
        if (headheight) {
            this.tablbeHeight = boxtop - headheight - 5
            $('#table1_wrapper .dataTables_scrollBody').height(this.tablbeHeight)
        }
        headheight = $('#table2_wrapper .dataTables_scrollHeadInner').height()
        if (headheight) {
            this.tablbeHeight = boxtop - headheight - 5
            $('#table2_wrapper .dataTables_scrollBody').height(this.tablbeHeight)
        }
    },
    pageLoad: function (geography, shiduan, geo_dim, city, area) {
        loading.show()
        /* if(geography){
            this.geographyChart(shiduan,geo_dim,city,area);
        } else{
            this.timeChart(shiduan, geo_dim, city, area);
        }
        this.chartTop(shiduan,geo_dim, city, area); */
        drawPage()
    },
    chartTop: function (shiduan, geo_dim, city, area) {
        var param
        if (geo_dim === '省') {
            param = {
                geo_dim: geo_dim,
                time_dim: shiduan,
                area: area
            }
        } else {
            param = {
                geo_dim: geo_dim,
                time_dim: shiduan,
                city: city,
                area: area
            }
        }
        service.get(getApiPath() + 'newWideTable/geographyChart',
            {
                params: param
            }
        ).then(function (res) {
            var res1 = res.data.widetable_m_1_1_list
            res = res.data.widetable_d_list
            try {
                setBaseVal(res)
                setBaseVal1(res1)
            } catch (e) {
                console.log(e)
            }
        }).catch(function (e) {
            return false
        })
    },
    geographyChart: function (shiduan, geo_dim, city, area) {
        var param
        if (geo_dim === '省') {
            param = {
                geo_dim: '地市',
                time_dim: shiduan,
                area: area
            }
        } else if (geo_dim === '地市' || geo_dim === '区县') {
            param = {
                geo_dim: '区县',
                time_dim: shiduan,
                city: city,
                area: area != '全量小区' ? area : ''
            }
            /* param = {
                geo_dim: geo_dim,//isDbClickMap ? geo_dim : '区县',
                time_dim: shiduan,
                city: city,
                area: area//area != '全量小区'? area : ''
            } */
        }
        getWideData(param, 'newWideTable/geographyChart')
    },
    timeChart: function (shiduan, geo_dim, city, area) {
        var param
        if (geo_dim === '省') {
            param = {
                geo_dim: geo_dim,
                time_dim: shiduan,
                area: area,
                num: shiduan == 'M' ? 6 : 7
            }
        } else {
            param = {
                geo_dim: geo_dim,
                time_dim: shiduan,
                city: city,
                area: area,
                num: shiduan == 'M' ? 6 : 7
            }
        }
        getWideData(param, 'newWideTable/timeChart')
    }
})
var page = new N.indexHome()
$(function () {
    loading.show()
    $(document).on('map:click', function (event, geography, shiduan, geo_dim, map_city, map_area) {
        page.pageLoad(geography, shiduan, geo_dim, map_city, map_area)
    })
    /* if(cityName == 'hebei'){
        page.pageLoad('','D', '省', undefined, '全量小区');
    }else{
        page.pageLoad('','D', '地市', cityName, '全量小区');
    } */
})

function cleanRes () {
    volte_voice_traffic = []
    upoct = []
    starttime = []
    geoDim = []
    high_load_num = []
    basic_comm_complain_ratio = []
    poor_coverage_cell_ratio = []
    mr_coverage_rate = []
    critical_alarm_ratio = []
    drawPage_Json = {}
    site_num_lte = []// 基站数
    cell_num_lte = []// 小区数
    hige_interfere_num = []
    radio_equipment_availability = []
}

function setBaseVal (res) {
    // $('#baseSiteNums').html(toThousands(res[0].site_num_lte));//基站数
    // $('#cellNums').html(toThousands(res[0].cell_num_lte));//小区数
    $('#hige_interfere_num_growthrate').html(toThousands(res[0].hige_interfere_num_growthrate) + '%')// 高干扰小区环比
    if (parseFloat(res[0].hige_interfere_num_growthrate) > 0) {
        $('#high_interfer_growthrate_arrow').removeClass('fa-long-arrow-down').removeClass('fa-long-arrow-up').addClass('fa-long-arrow-up')
        $('#high_interfer_growthrate_arrow').css('color', '#f83608')
    } else {
        $('#high_interfer_growthrate_arrow').removeClass('fa-long-arrow-down').removeClass('fa-long-arrow-up').addClass('fa-long-arrow-down')
        $('#high_interfer_growthrate_arrow').css('color', '#46d51a')
    }
    $('#hige_interfere_num').html(toThousands(res[0].hige_interfere_num))// 高干扰小区数
    $('#bad_cell_num_growthrate').html(toThousands(res[0].bad_cell_num_growthrate) + '%')// 劣化小区环比
    if (parseFloat(res[0].bad_cell_num_growthrate) > 0) {
        $('#bad_cell_growthrate_arrow').removeClass('fa-long-arrow-down').removeClass('fa-long-arrow-up').addClass('fa-long-arrow-up')
        $('#bad_cell_growthrate_arrow').css('color', '#f83608')
    } else {
        $('#bad_cell_growthrate_arrow').removeClass('fa-long-arrow-down').removeClass('fa-long-arrow-up').addClass('fa-long-arrow-down')
        $('#bad_cell_growthrate_arrow').css('color', '#46d51a')
    }
    $('#bad_cell_num').html(toThousands(res[0].bad_cell_num))// 劣化小区数
    // $('#lte_users').html(toThousands(res[0].lte_users));//4G客户数
    // $('#lte_users_dou').html(toThousands(res[0].lte_users_dou) + '(MB)');//4G客户DOU
    // $('#unlimited_lte_users').html(toThousands(res[0].unlimited_lte_users));//4G不限量客户数(万)
    // $('#bbu_online_rate').html(toThousands(res[0].bbu_online_rate));//BBU在网率  -名称改为->无线设备在网率
    // $('#radio_equipment_availability').html(toThousands(res[0].radio_equipment_availability));//无线设备可用率
}
function setBaseVal1 (res1) {
    $('#baseSiteNums').html(res1 ? toThousands(res1[0].site_num_lte) : '0')// 基站数
    $('#cellNums').html(res1 ? toThousands(res1[0].cell_num_lte) : '0')// 小区数
    $('#lte_users').html(res1 ? toThousands(res1[0].lte_users) : '0')// 4G客户数
    $('#lte_users_dou').html(res1 ? toThousands(res1[0].lte_users_dou) + '(MB)' : '0')// 4G客户DOU
    $('#unlimited_lte_users').html(res1 ? toThousands(res1[0].unlimited_lte_users) : '0')// 4G不限量客户数(万)
    $('#bbu_online_rate').html(toThousands(parseFloat(res1[0].bbu_online_rate).toFixed(2)))// BBU在网率  -名称改为->无线设备在网率
    $('#radio_equipment_availability').html(toThousands(parseFloat(res1[0].radio_equipment_availability).toFixed(2)))// 无线设备可用率
}

function getWideData (param, reqUrl) {
    console.log('时间维度:' + param.time_dim + '；地理纬度:' + param.geo_dim + '；省:' + HB_province + '；市:' + param.city + '；区县:' + param.area + '；请求地址:' + reqUrl)
    loading.show()
    service.get(getApiPath() + reqUrl,
        {
            params: param
        }
    ).then(function (res) {
        cleanRes()
        var res1 = res.data.widetable_m_1_1_list
        res = res.data.widetable_d_list
        if (res && res.length >= 1) {
            /* if(isSetBaseVal(reqUrl)){
                setBaseVal(res);
            } */
            for (var i = res.length - 1; i > -1; i--) {
                if (res[i].city != '不详' && res[i].area != '不详') {
                    setVal(res[i])
                }
            }
        }
        if (res1 && res1.length >= 1) {
            for (var i = res1.length - 1; i > -1; i--) {
                if (res1[i].city != '不详' && res1[i].area != '不详') {
                    setVal1(res1[i])
                }
            }
        }
        drawPage()
        loading.hide()
    }).catch(function (e) {
        return false
    })
}

function drawPage () {
    setVal()

    // 页面显示平均时长(整体)
    drawColumnColMax({
        id: 'line1',
        title: null,
        cate: $('#showFont').attr('geography') ? geoDim : starttime,
        data: [
            {
                name: '页面显示平均时长(ms)',
                type: 'areaspline',
                // color: N.Util.Theme_colors.blue,
                fillOpacity: 0.3, // 指定面积图的透明度
                marker: {
                    enabled: true,
                    symbol: 'circle',
                    radius: 2
                },
                data: yemian_time
            }
        ],
        marginTop: 30,
        marginBottom: 0,
        itemWidth: 110,
        lenabled: true,
        lenabledAlign: 'center',
        lenabledVerticalAlign: '',
        layout: 'horizontal',
        lenabledWidth: 10,
        chartType: 'column',
        // Yfloor: Math.min.apply(Math, upoct),
        Yfloor: 2200,
        YMax: 2400

    })
    // 页面显示平均时长(非整体)
    drawColumnCol({
        id: 'line2',
        title: null, // '页面显示平均时长(ms)',
        cate: $('#showFont').attr('geography') ? geoDim : starttime,
        data: [
            {
                name: '手机百度',
                type: 'line',
                marker: {
                    enabled: true, /* 数据点是否显示 */
                    radius: 4 /* 数据点大小px */
                },
                data: shjbd_time
            },
            {
                name: '腾讯网',
                type: 'line',
                marker: {
                    enabled: true, /* 数据点是否显示 */
                    radius: 4 /* 数据点大小px */
                },
                data: txw_time
            },
            {
                name: '今日头条',
                type: 'line',
                maxPointWidth: 15,
                data: jrtt_time
            }
        ],
        marginTop: 20,
        marginBottom: 20,
        itemWidth: 110,
        lenabled: true,
        lenabledAlign: 'center',
        lenabledVerticalAlign: 'top',
        layout: 'horizontal'
    })
    // 即时通信速率趋势
    drawColumnCol({
        id: 'line4',
        title: null, // '即时通信速率趋势(ms)',
        cate: $('#showFont').attr('geography') ? geoDim : starttime,
        data: [
            {
                name: 'IM图片发送速率(Kbps)',
                type: 'line',
                marker: {
                    enabled: true, /* 数据点是否显示 */
                    radius: 4 /* 数据点大小px */
                },
                data: pic_send_rate
            },
            {
                name: 'IM图片接收速率(Kbps)',
                type: 'line',
                marker: {
                    enabled: true, /* 数据点是否显示 */
                    radius: 4 /* 数据点大小px */
                },
                data: pic_receive_rate
            },
            {
                name: 'IM视频发送速率(Kbps)',
                type: 'line',
                maxPointWidth: 15,
                data: video_send_rate
            },
            {
                name: 'IM视频接收速率(Kbps)',
                type: 'line',
                marker: {
                    enabled: true, /* 数据点是否显示 */
                    radius: 4 /* 数据点大小px */
                },
                data: video_receive_rate
            }

        ],
        marginTop: 20,
        marginBottom: 20,
        itemWidth: 110,
        lenabled: true,
        lenabledAlign: 'center',
        lenabledVerticalAlign: 'top',
        layout: 'horizontal'
    })
    // 视频下载速率(整体)
    drawPage_Json = {
        id: 'line5',
        title: null,
        cate: $('#showFont').attr('geography') ? geoDim : starttime,
        data: [
            {
                name: '视频下载速率(kbps)',
                type: 'areaspline',
                // color: N.Util.Theme_colors.blue,
                fillOpacity: 0.3, // 指定面积图的透明度
                marker: {
                    enabled: true,
                    symbol: 'circle',
                    radius: 2
                },
                data: video_rate
            }
        ],
        marginTop: 30,
        marginBottom: 0,
        itemWidth: 110,
        lenabled: true,
        lenabledAlign: 'center',
        lenabledVerticalAlign: '',
        layout: 'horizontal',
        lenabledWidth: 10,
        chartType: 'column'
        // Yfloor: Math.min.apply(Math, upoct),
        // Yfloor2: 0

    }
    drawColumnCol(drawPage_Json)
    // 视频下载速率(非整体)
    drawColumnCol({
        id: 'line6',
        title: null, // '页面显示平均时长(ms)',
        cate: $('#showFont').attr('geography') ? geoDim : starttime,
        data: [
            {
                name: '咪咕视频',
                type: 'line',
                marker: {
                    enabled: true, /* 数据点是否显示 */
                    radius: 4 /* 数据点大小px */
                },
                data: migu_video_rate
            },
            {
                name: '抖音',
                type: 'line',
                marker: {
                    enabled: true, /* 数据点是否显示 */
                    radius: 4 /* 数据点大小px */
                },
                data: douyin_video_rate
            },
            {
                name: '腾讯视频',
                type: 'line',
                maxPointWidth: 15,
                data: tx_video_rate
            },
            {
                name: '爱奇艺视频',
                type: 'line',
                marker: {
                    enabled: true, /* 数据点是否显示 */
                    radius: 4 /* 数据点大小px */
                },
                data: aiqyi_video_rate
            },
            {
                name: '西瓜视频',
                type: 'line',
                marker: {
                    enabled: true, /* 数据点是否显示 */
                    radius: 4 /* 数据点大小px */
                },
                data: xg_video_rate
            },
            {
                name: '火山小视频',
                type: 'line',
                maxPointWidth: 15,
                data: hsh_video_rate
            }
        ],
        marginTop: 20,
        marginBottom: 20,
        itemWidth: 110,
        lenabled: true,
        lenabledAlign: 'center',
        lenabledVerticalAlign: 'top',
        layout: 'horizontal'
    })
    loading.hide()
}

function setVal (item) {
    starttime = [
        '10-29', '10-30', '10-31', '11-01', '11-02', '11-03', '11-04', '11-05', '11-06', '11-07', '11-08', '11-09', '11-10', '11-11'
    ]
    // 页面显示时长
    yemian_time = [2241.49, 2264.35, 2253.77, 2242.49, 2259.02, 2255.94, 2287.93, 2268.14, 2255.18, 2304.37, 2300.56, 2321.80, 2347.61, 2277.60]
    shjbd_time = [3729, 3707, 3709, 3727, 3722, 3740, 3760, 3734, 3745, 3746, 3748, 3782, 3784, 3793
    ]
    txw_time = [2371, 2328, 2365, 2356, 2372, 2398, 2433, 2365, 2376, 2374, 2668, 2462, 2446, 2424
    ]
    jrtt_time = [2154, 2129, 2139, 2156, 2168, 2170, 2156, 2188, 2188, 2183, 2184, 2184, 2188, 2187
    ]

    // 视频下载速率
    migu_video_rate = [2243.46, 2230.17, 2172.85, 2136.94, 2142.14, 2137.42, 2120.76, 2110.86, 2095.8, 2105.91, 2115.33, 2123.53, 2149.37, 2174.08
    ]
    douyin_video_rate = [
        1167.35, 1101.84, 1007.86, 1018.6, 976.44, 967.76, 963.6, 957.73, 952.28, 940.66, 916.54, 920.57, 938.03, 923.02
    ]
    tx_video_rate = [
        985.89, 969.34, 945.02, 963.66, 1000.45, 967.36, 943.22, 940.21, 1009.74, 905.35, 858.59, 857.73, 875.85, 886.74
    ]
    aiqyi_video_rate = [
        1664.35, 1602.75, 1565.05, 1535.92, 1500.75, 1471.73, 1444.82, 1447.15, 1438.23, 1404.18, 1382.05, 1376, 1384.69, 1377.9
    ]
    xg_video_rate = [
        988.6, 982.33, 962.83, 944.15, 932.76, 923.46, 912.57, 914.63, 910.12, 889.51, 887.83, 880.61, 887.61, 875.75
    ]
    hsh_video_rate = [
        899.29, 898.22, 882.23, 872.65, 847.3, 835.72, 829.56, 829.79, 829.24, 806.04, 777.34, 786, 781.07, 806.98
    ]
    video_rate = [
        2292.21, 1802.69, 1858.76, 1772.85, 1702.71, 1598.98, 1590.34, 1706.57, 1462.06, 1541.39, 1530.39, 1614.97, 1420.75, 1541.59
    ]

    // 即时通信速率趋势
    pic_send_rate = [
        595.61, 605.32, 584.65, 568.51, 562.12, 550.78, 511.28, 571.4, 560.67, 529.9, 529.11, 521.57, 525.6, 515.5
    ]
    pic_receive_rate = [
        663.23, 725.51, 725.43, 717.49, 722.6, 730.75, 672.79, 735.45, 738.62, 732.9, 718.17, 743.85, 699.21, 698.01
    ]
    video_send_rate = [
        774.69, 781.91, 738.98, 730.08, 728.46, 717.37, 723.56, 699.46, 721.74, 703.3, 694.3, 705.87, 724.92, 718.24
    ]
    video_receive_rate = [
        2021.79, 1997.55, 1951.58, 1955.59, 1954.95, 1946.64, 1890.84, 1965.54, 1938.84, 1922.7, 1947.54, 1950.7, 1931.64, 1938.71
    ]
}
function setVal1 (item) {
    site_num_lte.push(parseInt(item.site_num_lte))// 基站数
    cell_num_lte.push(parseInt(item.cell_num_lte))// 小区数
    basic_comm_complain_ratio.push(parseFloat(item.basic_comm_complain_ratio))
    mr_coverage_rate.push(parseFloat(item.mr_coverage_rate))
    poor_coverage_cell_ratio.push(parseFloat(item.poor_coverage_cell_ratio))
    critical_alarm_ratio.push(item.critical_alarm_ratio)
    radio_equipment_availability.push(parseFloat(item.radio_equipment_availability))
}

function isSetBaseVal (param) {
    // return (param.geo_dim === '省' && !param.city && param.area === '全量小区') || (param.geo_dim === '地市' && param.city && param.city != '全量小区' && param.area === '全量小区') || (param.geo_dim === '区县' && param.city && param.city != '全量小区' && param.area != '全量小区');
    return param === 'newWideTable/timeChart'
}
